package com.smartfast4j.redis;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * Redis客户端工厂
 *
 */
public class RedisClientFactory {

    private static Logger logger = Logger.getLogger(RedisClientFactory.class);

    private static class RedisFactoryHolder {

        private static Map<RedisName, JedisClient> jedisClientMap;

        static {
            jedisClientMap = new HashMap<>();
            jedisClientMap.put(RedisName.JEDIS_CLIENT_CLUSTER, JedisClientCluster.getInstance());
            jedisClientMap.put(RedisName.JEDIS_CLIENT_SINGLE, JedisClientSingle.getInstance());
        }
    }

    /**
     * 默认缓存实现
     *
     * @return
     */
    public static JedisClient getDefaultRedisClient() {
        logger.info("默认采用的Redis实现为：" + RedisName.JEDIS_CLIENT_SINGLE);
        return RedisFactoryHolder.jedisClientMap.get(RedisName.JEDIS_CLIENT_SINGLE);
    }

    public static JedisClient getRedisClient(RedisName redisName) {
        logger.info("当前采用的Redis实现为：" + redisName.name());
        return RedisFactoryHolder.jedisClientMap.get(redisName);
    }

}
